<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

get_config_keytable("office_mail_Increase");
empty($do) && $do = 'list';
if ($do == 'list') {
	include_once('template/add.php');

} elseif ($do == 'save') {

  global $db;
  $mailsignature = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."mailsignature  WHERE uid = '$_USER->id'");

   $savetype = getGP('savetype','P');
   //接收参数
   $savetype = getGP('savetype','P');
   $title = getGP('title','P');
   $rqmail = getGP('rqmail','P');
   $annexurl = getGP('annexurl','P');
   $content = getGP('content','P');
   $sendmail=explode('/',getGP('sendmail','P'));
   $smtp=explode('@',$sendmail[2]);
   //调用参数
   $_smtp=$smtp[1];
   $_username=$sendmail[0];
   $_password=$sendmail[1];
   $_emailaddress=$sendmail[2];
   $_name=$sendmail[3];
   $contents=$content."<br>".$mailsignature[content];
   $titles='发送电子邮件';
   get_oa_log_dbadd('10',$contents,$titles,5,$_USER->id);

   //发送邮件
   require("class.phpmailer.php"); 
   $mail = new PHPMailer();  
   $mail->IsSMTP();                 // 启用SMTP
   $mail->CharSet = "utf-8"; // 这里指定字符集！
   $mail->Encoding = "base64"; 
   $mail->Host = "smtp.".$_smtp;           //SMTP服务器 
   $mail->SMTPAuth = true;                  //开启SMTP认证
   $mail->Username = $_username;            // SMTP用户名 
   $mail->Password = $_password;                // SMTP密码   
   $mail->From = $_emailaddress;            //发件人地址 
   $mail->FromName = "=?UTF-8?B?" . base64_encode($_name) . "?=";              //发件人 
   $rqmails=explode(',',$rqmail);
   for($mi=0;$mi<sizeof($rqmails);$mi++)
	{
   //$mail->ClearAddresses();
   $mail->AddAddress($rqmails[$mi]); //添加收件人 
   }
   //$mail->AddAddress($rqmail); 
   $mail->AddReplyTo($_emailaddress, $_name);    //回复地址 
   $mail->WordWrap = 50;                    //设置每行字符长度
    //附件设置 
	if($annexurl!=''){
	$mail->AddAttachment($annexurl,"=?UTF-8?B?" . base64_encode("附件下载") . "?=");
	}
   //$mail->AddAttachment("var/21.bmp");        // 添加附件 
   //$mail->AddAttachment("/var/21.bmp", "通用公文收文使用说明");   // 添加附件,并指定名称 
   $mail->IsHTML(true);                 // 是否HTML格式邮件   
   $mail->Subject = "=?UTF-8?B?" . base64_encode($title) . "?=";          //邮件主题 
   $mail->Body    = $content."<br>".$mailsignature[content];        //邮件内容 
   $mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //邮件正文不支持HTML的备用显示 
   if(!$mail->Send()) {    echo "Message could not be sent. <p>";    echo "Mailer Error: " . $mail->ErrorInfo;    exit; }   echo "邮件己成功发送到".$rqmail."中";
	
	
   // echo '<script language="JavaScript">window.close();window.opener.location.reload();/script>';

}
?>